/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.action.phonenumber;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import apus.action.Action;
import apus.action.ActionResult;
import apus.entity.PhoneNumber;
import apus.persistence.PhoneNumberDAO;
import apus.services.ServiceLocator;
import java.util.ArrayList;

/**
 *
 * @author Admin
 */
public class PhoneNumberListAction implements Action {

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        List<PhoneNumber> phoneNumberList = ServiceLocator.getService(PhoneNumberDAO.class).findAll();
        if (request.getParameter("sub_id") != null) {
            Integer sub_id = Integer.parseInt(request.getParameter("sub_id"));
            List<PhoneNumber> tmpList = new ArrayList<PhoneNumber>();
            for (PhoneNumber phoneNumber : phoneNumberList) {
                if (phoneNumber.getOwner().getId() == sub_id) {
                    tmpList.add(phoneNumber);
                }
            }
            phoneNumberList=tmpList;
        }
        request.setAttribute("phoneNumberList", phoneNumberList);
        return ActionResult.forward("/WEB-INF/View/PhoneNumberView/PhoneNumberListView.jsp");
    }

    @Override
    public String getName() {
        return "phoneNumber.list";
    }
      
}